﻿
@{
    ViewBag.Title = "菜单管理";
}

<div class="container-fluid layout-box main-box">
    <div class="layout-top">
        <button type="button" id="btnmenu-add" class="btn btn-default">添加子节点</button>
        <button type="button" id="btnmenu-edit" class="btn btn-default">编辑节点</button>
        <button type="button" id="btnmenu-del" class="btn btn-default ">删除节点</button>
    </div>
    <div class="row-fluid layout-center">
        <div class="span4" style="height:100%;overflow-y:scroll;">
            <ul id="div_tree_box"></ul>
        </div>
        <div class="span8" style="height:100%">
            <form id="formmenu" action="IMenu/SaveMenu" method="post" fm-form='ajax' role="form">
                <div class="form-group">
                    <label>父级菜单id</label>
                    <input type="text" id="txtParentId" name="ParentId" class="form-control" placeholder="父级菜单id">
                </div>
                <div class="form-group">
                    <label>菜单名称</label>
                    <input type="text" fm-null="菜单名称不能为空！" name="Name" class="form-control" placeholder="菜单名称">
                </div>
                <div class="form-group">
                    <label>链接</label>
                    <input type="text" name="Target" class="form-control" placeholder="链接">
                </div>
                <div class="form-group">
                    <label>icon类名</label>
                    <input type="text" name="CssIcon" class="form-control" placeholder="icon类名">
                </div>
                <div class="form-group">
                    <label>权重</label>
                    <input type="text" name="Weight" class="form-control" placeholder="权重">
                </div>
                <div class="form-group">
                    <label>是否控制</label>
                    <select class="form-control" name="IsAction">
                        <option value="false">否</option>
                        <option value="true">是</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>排序号</label>
                    <input type="text" fm-null="排序号不能为空！" name="SortCode" class="form-control" placeholder="排序号">
                </div>
                <input type="hidden" name="ID" value="" />
                <button type="reset" class="btn btn-default">重置</button>
                <button type="submit" class="btn btn-default">提交</button>
            </form>
            <div style="margin-top:20px;">
                <div id="uploadfo"></div><button class="btn " id="btnImport">导入</button>
            </div>
        </div>
    </div>
</div>

@section Scripts{
    <script type="text/javascript">
        var selNode;
        var app = $("#div_tree_box").uTree({
            async: {
                enable: true,
                url: "/IMenu/GetMenuTree"
            },
            check: {
                enable: false
            },
            view: { expand: 5 },
            data: {
                key: {
                    name: "menuName",
                    children: "childs"
                },
                simpleData: {
                    idKey: "menuId"
                }
            },
            callback: {
                onClick: function (e, treeId, treeNode) {
                    selNode = treeNode;
                    var pnode = treeNode.getParentNode();
                }
            }
        });

        $("#formmenu").Form({
            success: function (d) {
                location.reload();
            }
        });
        //保存
        $("#btnmenu-add").click(function () {
            $("#txtParentId").val(selNode.menuId);
        });
        //获取编辑节点
        $("#btnmenu-edit").click(function () {
            $("#formmenu").find("input[name=ParentId]").val(selNode.parentId);
            $("#formmenu").find("input[name=CssIcon]").val(selNode.menuicon);
            $("#formmenu").find("input[name=Name]").val(selNode.menuName);
            $("#formmenu").find("input[name=ID]").val(selNode.menuId);
            $("#formmenu").find("input[name=Target]").val(selNode.target);
            $("#formmenu").find("input[name=SortCode]").val(selNode.sortCode);
            $("#formmenu").find("input[name=Weight]").val(selNode.Weight);
            $("#formmenu").find("select[name=IsAction]").find("option[value=" + selNode.IsAction + "]").attr("selected", true);
        });

        ///删除
        $("#btnmenu-del").click(function () {
            $.msg.confirm("确定要删除吗？", function () {
                $.get("IMenu/Delete", { id: selNode.menuId }, function (d) {
                    location.reload();
                });
            });
        });

        $('#uploadfo').jsUpload({
            autoUpload: true,
            request: {
                endpoint: '/Upload/QQUpLoadFile'
            },
            validation: {
                allowedExtensions: ["xlsx", "xls"],
                sizeLimit: 0
            },
            callbacks: {
                onComplete: function (id, fileName, data) {
                    $("#btnImport").removeClass("hide");
                    filepath = data.file;
                }
            }
        });
        var filepath = "";
        $("#btnImport").click(function () {
            $.get("/IMenu/ImportExcel", { filepath: filepath }, function (data) {
                if (data.error == 0) {
                    $.msg.alert(data.msg);
                }
            });
        });
    </script>
}

